package cn.young.javalearning.designpattern.strategy.simpleStrategy.pro;

import cn.young.javalearning.designpattern.strategy.simpleStrategy.Shopping;

public enum ShoppingStrategyFacotryEnum {
    CAISHICHANG_STRATEGY("菜市场", "CaiShiChangStrategy", null),
    SHANGCHUANG_STRATEGY("商场", "ShangChangStrategy", null),
    MOREN_STRATEGY("默认", "Shopping", new Shopping() {});
    private String name;
    private String className;
    private Shopping shoppingStrategy;
    public String getName() {
        return name;
    }

    public Shopping getShoppingStrategy() {
        if(null == shoppingStrategy){
            try {
                Class<?> aClass = Class.forName("cn.young.javalearning.designpattern.strategy.simpleStrategy." + className);
                shoppingStrategy = (Shopping) aClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return shoppingStrategy;
    }

    ShoppingStrategyFacotryEnum(String name, String className, Shopping shoppingStrategy) {
        this.name = name;
        this.className = className;
        this.shoppingStrategy = shoppingStrategy;
    }
}
